package com.bclz.netty.websocket;


import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.util.concurrent.ImmediateEventExecutor;

public class WebSocketServer {

        private final ChannelGroup channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);

        private static final int PORT_NUMBER=19995;

        public static void main(String[] args) {
                EventLoopGroup bossGroup =new NioEventLoopGroup(1);
                EventLoopGroup workerGroup =new NioEventLoopGroup();

                ServerBootstrap serverBootstrap = new ServerBootstrap()
                        .group(bossGroup, workerGroup)
                        .channel(NioServerSocketChannel.class)
                        .childHandler(new WebSocketChannelInitializer());
                try {
                        Channel channel = serverBootstrap.bind(PORT_NUMBER).sync().channel();
                        channel.closeFuture().sync();
                } catch (InterruptedException e) {
                        System.out.println("发生错误...");
                }finally {
                        bossGroup.shutdownGracefully();
                        workerGroup.shutdownGracefully();
                }


        }


}
